import requests
import base64
from Crypto.Cipher import AES
import json


def unpad(s):
    return s[: -s[-1]]


# 你的请求头，可按实际调整
headers = {
    "Host": "ios.jingyeqian.com",
    "Accept": "*/*",
    "clientVersion": "3.4.10",
    "signature": "123456",
    "timestamp": "1753936770",
    "User-Agent": "jing ye qian/3.4.10 (iPhone; iOS 15.8.3; Scale/2.00)",
    "accessToken": "juNQeZKXQ8rOAbkstPTjtLDa+uWlmMKmPPyA4zeG5/sYo01wgzl5ripUd5EmHdh+xPcZnTZMr2ueCVgs2bETyssNRI0D0a0zdqzZuQipl6Pt3QHyBSTjuhj800AJKxdiKNNDQktQioVf25ln69BfmI7yVyAJxdeB",
    "appId": "jyqios",
    "Accept-Language": "zh-Hans-CN;q=1",
}

url = "https://ios.jingyeqian.com/user/userInfo"

# 获取响应
response = requests.get(url, headers=headers)
print("加密响应原文：")
print(response.text)

try:
    # 先解析整个json
    resp_json = response.json()
    if "data" not in resp_json:
        print("响应中未找到data字段！")
        exit(1)
    ciphertext_b64 = resp_json["data"]

    # 加密参数（你的frida日志中Key的hex串）
    key_hex = "3637336130616231653066613364323639303066316337366164346135303837"
    key = bytes.fromhex(key_hex)

    # 解密
    ciphertext = base64.b64decode(ciphertext_b64)
    cipher = AES.new(key, AES.MODE_ECB)
    plaintext = cipher.decrypt(ciphertext)
    real_data = unpad(plaintext)
    # 自动尝试转为utf8后打印（明文大多为json）
    try:
        print("解密明文：")
        print(real_data.decode("utf-8"))
    except Exception:
        print("明文无法直接utf-8解码，尝试查看hex：")
        print(real_data.hex())
except Exception as e:
    print(f"解密过程出错：{e}")
